<script lang="ts" setup>
import PageTable from "@/components/PageTable/index.vue";
import SearchHeader from "@/components/SearchHeader/index.vue";
import PageContainer from "@/components/PageContainer/index.vue";
import {reactive, ref} from "vue";
import {Brush, Edit, View} from '@element-plus/icons-vue'
import SupportingDialog from "@/views/project/components/SupportingDialog.vue";
import {ButtonColor} from "@/utils/buttonsColor";
import {delProject, stationList} from "@/api/demoApi";
import {message} from "@/utils/message";

defineOptions({
  name: "supporting"
});

/**-------------------搜索-------------------**/
//查询参数
const queryList = [
  {key:'projectNo',label:'更新后编号',type:'input'},
  {key:'projectName',label:'规划站名',type:'input'},
  {key:'projectName',label:'建设状态',type:'select',options:[
      {label:'待指派',value: 1},
      {label:'待配套',value: 2},
      {label:'待开通',value: 3},
      {label:'已开通',value: 4},
    ]},
]
//分页
const pageQuery = reactive({
  page:1,
  size:15
})
//查询回调
const searchHandler = (queryForm)=>{
  console.log(queryForm)
}
//分页回调
const paginationHandler = (pageInfo) =>{
  pageQuery.page = pageInfo.page
  pageQuery.size = pageInfo.size
}

/**-------------------列表-------------------**/
//总条数
const total = ref(0)
//表格列
const tableColumns = [
  {label:'更新后编号',key:'stationNo'},
  {label:'规划站名',key:'planName'},
  {label:'所属项目',key:'projectName'},
  {label:'塔桅产权方',key:'towerAdmin'},
  {label:'塔桅类型',key:'towerType'},
  {label:'机房产权方',key:'roomAdmin'},
  {label:'机房类型',key:'roomType'},
  {label:'市电产权方',key:'eleAdmin'},
  {label:'配套资料附件',key:'files',custom:true},
  {label:'配套完成时间',key:'buildTime'},
  {label:'建设状态',key:'status',custom:true},
  {label:'操作',key:'operation',custom:true,width: 250}
]
//表格行数据
const tableData = ref([])
const getTableData = ()=>{
  tableData.value = stationList()
}
getTableData()

/**-------------------操作-------------------**/
//弹窗
const supportingDialog = ref()
const openDialog = (type:string,row:object)=>{
  switch (type){
    case 'supporting':
      supportingDialog.value.dialogShow('配套完成',row)
      break
    case 'edit':
      supportingDialog.value.dialogShow('配套编辑',row)
      break
  }
}
//未完成提示
const notDone = ()=>{
  message('抱歉，功能设计中...',{type:'warning'})
}
</script>

<template>
  <PageContainer>
    <!--顶部筛选-->
    <SearchHeader :query-list="queryList" @search="searchHandler" />
    <!--    表格-->
    <PageTable :columns="tableColumns" :page="pageQuery.page" :size="pageQuery.size" :table-data="tableData" :total="total" @pagination="paginationHandler">
      <template #files="{row}">
        <el-button size="small" text type="primary" @click="notDone">查看</el-button>
      </template>
      <template #status="{row}">
        <el-tag v-if="row.status===1" type="primary">待指派</el-tag>
        <el-tag v-if="row.status===2" type="primary">待配套</el-tag>
        <el-tag v-if="row.status===3" type="primary">待开通</el-tag>
        <el-tag v-if="row.status===4" type="primary">已开通</el-tag>
      </template>
      <template #operation="{row}">
        <el-button :color="ButtonColor.VIEW" :icon="View" plain round size="small" @click="notDone">查看</el-button>
        <el-button v-if="row.status===2" :color="ButtonColor.EDIT" :icon="Brush" plain round size="small" @click="openDialog('supporting',row)">配套完成</el-button>
        <el-button v-if="row.status===3 || row.status===4" :color="ButtonColor.EDIT" :icon="Edit" plain round size="small" @click="openDialog('edit',row)">配套编辑</el-button>
      </template>
    </PageTable>

    <!--  弹窗-->
    <SupportingDialog ref="supportingDialog" @done="getTableData" />
  </PageContainer>
</template>

<style lang="scss" scoped>

</style>
